﻿						<div class="box border green">
									<div class="box-title">
										<h4><i class="fa fa-table"></i>新闻列表</h4>
										<div class="tools hidden-xs">
											<a href="#box-config" data-toggle="modal" class="config">
												<i class="fa fa-cog"></i>
											</a>
											<a href="javascript:;" class="reload">
												<i class="fa fa-refresh"></i>
											</a>
											<a href="javascript:;" class="collapse">
												<i class="fa fa-chevron-up"></i>
											</a>
											<a href="javascript:;" class="remove">
												<i class="fa fa-times"></i>
											</a>
										</div>
									</div>
									<div class="box-body">
										<table id="" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th class="center">#</th>
													<th class="">name</th>
													<th class="center">Pid</th>

													<th class="center">操作</th>

												</tr>
											</thead>
											<tbody>
												<?php
													if(!empty($cate)){
													foreach($cate as $v){?>
													<tr class="gradeX " pid ="<?php echo $v['pid']?>" lv="1">
														<td class="center"><?php echo $v['id']?></td>
														<td class="" ><button class="btn btn-pink bbt">+</button><?php echo $v['name']?></td>
														<td class="center "><?php echo $v['pid']?></td>

														<td class="center hidden-xs" style="width:160px">
															<a href="index.php?c=cate&a=edit&admin=1&id=<?php echo $v['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i>编辑</a>
															<a class="btn btn-danger del" href="index.php?c=cate&a=del&id=<?php echo $v['id']?>" onclick="return confirm('确定要删除吗');"><i class="fa fa-trash-o"></i>删除</a>
														</td>
													</tr>
												<?php }}?>
											</tbody>

										</table>
										<div class="row">
											<div class="col-sm-12">
												<div class="pull-left">
													<div class="dataTables_info" id="datatable1_info">Showing 1 to 9 of 9 entries</div>
												</div>
												<div class="pull-right">
												    <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
												   		<ul class="pagination">
															<!-- 翻页标签 -->
									   					</ul>
								   					</div>
												</div>
												<div class="clearfix"></div>
											</div>
										</div>
									</div>
								</div>

<script src="resources/admin/js/jquery/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
				/*给+号按钮绑定点击事件*/
				$('tbody').on('click','.bbt',function(){

						var text=$(this).text();

						var id =$(this).parent().prev().text();
						var pid =$(this).parent().next().text();

						// 避免重新给类为gradeX的标签之后添加tr，这里的tr用变量代替
						var obj=$(this).parent().parent();

						var lv = obj.attr('lv');
						    lv++;

						if(text=='+'){
							$(this).text('-');
							var html='';
							$.ajax({
							type:'get',
							url:'index.php?c=cate&a=list&admin=1&id='+id,
							dataType:'json',
							success:function(json){


								for(i in json){
									var jpid = json[i].pid;
									html+='<tr class="gradeX" pid ="'+json[i].pid+'" lv="'+lv+'">';
									html+='<td class="center">'+json[i].id+'</td>';
									html+='<td class="" ><button class="btn btn-pink bbt" style="margin-left:'+(lv-1)*30+'px;">+</button>'+json[i].name+'</td>';
									html+='<td class="center ">'+json[i].pid+'</td>';
									html+='<td class="center hidden-xs" style="width:160px">';
									html+='	<a href="index.php?c=cate&a=edit&admin=1&id='+json[i].id+'" class="btn btn-info"><i class="fa fa-pencil-square-o"></i>编辑</a>';
									html+='	<a class="btn btn-danger del" href="index.php?c=cate&a=del&id='+json[i].id+'"onclick="return confirm(确定要删除吗);"><i class="fa fa-trash-o"></i>删除</a>';
									html+='</td></tr>';
								}

									html+='<tr pid="'+jpid+'" style="display:none;"></tr>';
									obj.after(html);
								}



							})
						}else{
							$(this).text('+');
							$(this).parent().parent().nextUntil('tr[pid="'+pid+'"]').remove();
						}


					})



				/*给删除标签绑定点击事件*/
				$('.del').click(function(){

					/*获取当前标签的href属性值*/
					var url = $(this).attr('href');

					//alert(url);return false;
					//
					/*提交ajax请求，把获取到带有id的地址进行提交*/
					$.ajax({
						type:'get',
						url:url,
						success:function(json){
							if(json>0){
								if(confirm('该级别下存在子级，确定删除吗？')){
									location.href=url;//此时将执行del文件的del函数
								}
							}else{
									location.href=url;//此时将执行del文件的del函数
								}
						}
					})
					return false;
				})
</script>